package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;

import mapper.NewsRowMapper;

import org.springframework.jdbc.core.JdbcTemplate;
import bean.News;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

public class newsDAO {
	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	public List<Object> selectAllSocialNews (){
		String sql = "select title,content from xahoi";
		return jdbcTemplate.query(sql,new NewsRowMapper());
	}
/*	public ArrayList<News> getNewsContent() {

		String sql = "select * from xahoi";
		ArrayList<News> nc = (ArrayList<News>) jdbcTemplate.query(sql, new NewsContentMapper());
		return nc;
	}

	private class NewsContentMapper implements
			ParameterizedRowMapper<News> {
		@Override
		public News mapRow(ResultSet rs, int row)
				throws SQLException {
			
			News n = new News();
			n.setTitle(rs.getString("title"));
			System.out.println(n.getTitle());
			n.setContent(rs.getString("content"));
			System.out.println(n.getTitle());
			return n;
		}

	}
*/
	
}
